/*
 * ReadFile.java
 *
 * Created on 5 février 2009, 15:22
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.yournamehere.server;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;

/**
 *
 * @author Titi
 */

public class ReadFile {
    BufferedReader reader;

    public ReadFile(String fileName) {
        try {

        reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
        } catch (FileNotFoundException e) {
        e.printStackTrace();
        }
    }

    public int[][] getData(int niveau) {
        String line;
        int[][] tab = new int[9][9];
        int[] lineTab = new int[9];
        try {
            for(int i=0; i<niveau; i++) {
                line = reader.readLine();
            }
            for(int i=0; i<9; i++) {
                line = reader.readLine();
                if (!line.equals("")){
                    lineTab = getGrid(line);
                }
                tab[i] = lineTab;
            }
            reader.close();
            return tab;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    private int[] getGrid(String line) {
        int[] lineTab = new int[9];
        String number = "";

        for(int i=0;i<9;i++){
            number = line.substring(0, line.indexOf(';'));
            line = line.replaceFirst(number + ';', "");
            lineTab[i] = Integer.parseInt(number);
            
        }
        return lineTab;
    }

 
}